// pages/search/search.js
Page({

  data: {
    flower:[],
    T:true,
    F:false
  },

  onLoad: function (option) {
    wx.setNavigationBarTitle({
      title: '搜索',
    })
    let {id} = option
    this.onShow(id)
  },
 onShow:function(id){
  const db = wx.cloud.database()
   let that = this
  db.collection('flower').orderBy('gross','desc').limit(10).get({
    success(res){
      that.setData({
        flower:res.data
      })
    }
  })
 },

   //接受输入事件
   inputEvent(res){
    var that = this
    let con = res.detail.value
    if (con == "") {
      con = "############"
      
    }
    //驱动云数据库
    const db = wx.cloud.database()
    const _ = db.command
    db.collection('flower').where(_.or([
      {
        title:db.RegExp({
          regexp:con,
          options:'i'
        })
      },
      {
        genre:db.RegExp({
          regexp:con,
          options:'i'
        })
      },
    ])).get({
      success(res){
       that.setData({
         flower:res.data,
         F:true,
        T:false
       })
      }
    })
 
   },
   
   submitEvent:function(res){
    console.log(res.detail.value)
    var con=res.detail.value.content
    wx.navigateTo({
      url:'../pages01/pages01',
    })
  }
})